package script;

import domain.User;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class CollectionExample {

    public static void main(String[] args) {

        User user = new User();

        ExpressionParser parser = new SpelExpressionParser();
        EvaluationContext context = new StandardEvaluationContext(user);

        int[] array1 = (int[]) parser.parseExpression("new int[]{1,2,3}").getValue();
        System.out.println(Arrays.asList(array1));

        int[][] array2 = (int[][]) parser.parseExpression("new int[2][3]").getValue();
        System.out.println(Arrays.asList(array2));


        List list = (List) parser.parseExpression("{1,2,3,4}").getValue(context);
        System.out.println(list);
        List listOfList = (List) parser.parseExpression("{{'a', 'b'}, {'x','y'}}").getValue(context);
        System.out.println(listOfList);

        Map userInfo = (Map) parser.parseExpression("{userName:'Tom',credits:100}").getValue(context);
        System.out.println(userInfo);

        List userInfo2 = (List) parser.parseExpression("{{userName:'tome', credits:100}, " +
                "{userName:'tome', credits:100}}").getValue(context);
        System.out.println(userInfo2);

        String interest1 = (String) parser.parseExpression("interestsArray[0]").getValue(context);
        System.out.println(interest1);

        String interest2 = (String) parser.parseExpression("interertsList[0]").getValue(context);
        System.out.println(interest2);

        String inerest3 = (String) parser.parseExpression("interertsMap ['A']").getValue(context);
        System.out.println(inerest3);

    }

}
